package com.example.rabbitmqbootproducer.controller;

import com.example.rabbitmqbootproducer.dto.MessageDTO;
import com.example.rabbitmqbootproducer.dto.ResultDTO;
import com.example.rabbitmqbootproducer.service.SendMessageService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 发送消息
 *
 * @author 伯路平
 * @since 2023/6/19
 **/
@RestController
@RequestMapping("/message")
@Validated
@Slf4j
@RequiredArgsConstructor
public class sendMessageController {

    private final SendMessageService sendMessageService;

    @PostMapping("/direct")
    public ResultDTO sendDirectMessage(@RequestBody @Valid MessageDTO messageDTO) {
        log.info("接收直连到消息体为：{}", messageDTO);
        sendMessageService.sendDirectMessage(messageDTO);
        return ResultDTO.builder().desc("发送成功").build();
    }

    @PostMapping("/fanout")
    public ResultDTO sendFanoutMessage(@RequestBody @Valid MessageDTO messageDTO){
        log.info("接收到广播消息体为：{}", messageDTO);
        sendMessageService.sendFanoutMessage(messageDTO);
        return ResultDTO.builder().desc("发送成功").build();
    }

    @PostMapping("/notExistExchange")
    public ResultDTO sendNotExistExchange(@RequestBody @Valid MessageDTO messageDTO){
        log.info("接收到广播消息体为：{}", messageDTO);
        sendMessageService.sendNotExistExchange(messageDTO);
        return ResultDTO.builder().desc("发送成功").build();
    }

    @PostMapping("/notBindingQueue")
    public ResultDTO notBindingQueue(@RequestBody @Valid MessageDTO messageDTO){
        log.info("接收到广播消息体为：{}", messageDTO);
        sendMessageService.notBindingQueue(messageDTO);
        return ResultDTO.builder().desc("发送成功").build();
    }

    @PostMapping("/errorBindingQueue")
    public ResultDTO errorBindingQueue(@RequestBody @Valid MessageDTO messageDTO){
        log.info("接收到广播消息体为：{}", messageDTO);
        sendMessageService.errorBindingQueue(messageDTO);
        return ResultDTO.builder().desc("发送成功").build();
    }

    @PostMapping("/expired")
    public ResultDTO expiredQueue(@RequestBody @Valid MessageDTO messageDTO){
        log.info("接收到广播消息体为：{}", messageDTO);
        sendMessageService.expiredQueue(messageDTO);
        return ResultDTO.builder().desc("发送成功").build();
    }

}
